<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>会员促销列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<div class="container">

   
        <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>促销名称：<input type="text" id="title" class="form-control input-sm"  name="title" value="" style="width:148px;"/></span>
                                    <span>
                                        活动类型：<select id="source" class="form-control input-sm"  name="source" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1">注册</option>
                                            <option value="2">登录</option>
                                            <option value="4">建议</option>
                                            <option value="5">问卷调查</option>
                                            <option value="6">完善资料</option>
                                            <option value="7">商品评论</option>
                                        </select>
                                    </span>
                                    <span>
                                        促销类型：<select id="type" class="form-control input-sm"  name="type" style="width:100px;">
                                            <option value="">请选择</option>
                                            <option value="1">送积分</option>
                                            <option value="2">送优惠券</option>
                                        </select>
                                    </span>
                                    <span>促销日期：<input id="startDate" class="form-control input-sm"  name="startDate" value="" type='text' style="width:120px;" readonly ></span>
                                    <button type="button" class="btn btn-default btn-sm" onclick="promotion.timeClear();">清 空</button>
                                    <span><input type="button" value="查询" class="btn btn-primary" onclick="promotion.search();" /></span>
                                    <span><input class="btn btn-warning" id="startDateBtn" name="startDateBtn" type="button" onclick="promotion.clear()" value="重置"></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/promotion/promotionCustomer.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            <!--{if $edit_permission}-->
            {display: "操作", width : 100, align: "center"},
            <!--{/if}-->
            {display: "促销号", name : "promotionID", width : 100, sortable : true,align:"right"},
            {display: "促销标题", width : 260},
            {display: "活动类型", width : 120},
            {display: "促销类型", width : 120},
            {display: "开始日期", width : 150 , align: "center"},
            {display: "结束日期", width : 150 , align: "center"},
            <!--{if $edit_permission}-->
            {display: "状态", width : 70,align:"center"}
            <!--{/if}-->
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "promotion.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "promotion.delConfirm"},
            {separator: true},
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
        ],
        <!--{/if}-->
        sortname: "promotionID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var promotion = {

        delArr: new Array(),

        promotionID:'',

        useFlg:'',

        //搜索会员促销
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //添加订单促销
        add: function() {
            E.open("/quanliadmin/app/promotion/promotionCustomer.pscript?operFlg=100", "", {height: 400,width: 900, top: 50, left: 150});
        },

        edit: function(promotionID) {
            E.open("/quanliadmin/app/promotion/promotionCustomer.pscript?operFlg=101&promotionID=" + promotionID, "", {height: 400,width: 900, top: 50, left: 150});
        },

        delConfirm: function() {
            //获取选中的行的行数
            var selected_count = $('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert('请选择要删除的促销');
                return;
            }else{
                var tempArr = new Array();
                for(var i=0; i<selected_count; i++){
                    var promotionStr = $('.trSelected',flex).eq(i).attr('id');
                    var promotionID = promotionStr.substr(3);
                    tempArr.push(promotionID);
                }
                this.delArr = tempArr;

                //弹出确认层
                E.confirm('确认删除这 ' + $('.trSelected',flex).length + ' 个促销吗?', "promotion.del");
            }
        },

        del: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/promotionCustomer.ajax?operFlg=100&act=del",
                dataType: "JSON",
                data:{delArr: promotion.delArr},
                success: function(result_obj){
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "promotion.load");
                    }
                    else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //禁用启用确认
        changeConfirm: function(promotionID , flg) {

            this.promotionID = promotionID;
            this.useFlg      = flg;

            if( flg == 0 ){
                E.confirm("您确认 启用 吗？", "promotion.change");
            }else{
                E.confirm("您确认 禁用 吗？", "promotion.change");
            }

        },

        //禁用启用
        change: function() {
            jquery_ajax(100 , {promotionID:this.promotionID,flg:this.useFlg} , promotion.callback );
        },

        //回调函数
        callback: function( obj ) {

            if( obj.code == 200 ){
                E.alert( obj.message , 2 , 'promotion.load' );
            }else{
                E.alert(obj.message);
            }

        },

        clear:function (){
            $("#title").val("");
            $("#source").val("");
            $("#startDate").val("");
            $("#type").val("");
            this.search();
        },

        timeClear: function() {
            $('#startDate').val('');
        },

        load: function() {
            $("#flex").flexReload();
        }

    };

    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/promotion/promotionCustomer.ajax?operFlg="+flg+"&act=change",
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                alert('网络不给力，请重新尝试...');
            }
        });
    }

    $('#startDate').datetimepicker();

</script>

</body>
</html>